package com.xbongbong.pro.statistic.service.result;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.TimeConstant;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.redis.RedisConstant;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import com.xbongbong.paas.redis.RedisTimeConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.Arith;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.paas.toolbox.util.JsonHelperUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.ElasticConstant;
import com.xbongbong.pro.domain.entity.ChartEntity;
import com.xbongbong.pro.enums.TimeTypeEnum;
import com.xbongbong.pro.service.toolbox.statistic.util.ChartResultUtil;
import com.xbongbong.pro.statistic.constant.ChartI18Constant;
import com.xbongbong.pro.statistic.enums.PanoramaEnum;
import com.xbongbong.pro.statistic.enums.SystemCodeEnum;
import com.xbongbong.pro.statistic.enums.ValueTypeEnum;
import com.xbongbong.pro.statistic.pojo.FiscalYearTimePojo;
import com.xbongbong.pro.statistic.result.pojo.AggsBucketsPojo;
import com.xbongbong.pro.statistic.result.pojo.ChartResultPkPojo;
import com.xbongbong.pro.statistic.result.pojo.ChartResultPojo;
import com.xbongbong.pro.statistic.result.pojo.ChartResultRedisPojo;
import com.xbongbong.pro.statistic.result.pojo.ElasticAggsPojo;
import com.xbongbong.pro.statistic.result.pojo.PanoramaPojo;
import com.xbongbong.pro.statistic.result.pojo.dto.StatisticResultPieInfoDTO;
import com.xbongbong.pro.statistic.result.pojo.vo.ChartResultDetailVO;
import com.xbongbong.pro.statistic.result.pojo.vo.ChartResultPkDetailVO;
import com.xbongbong.pro.statistic.result.pojo.vo.ResultCountListVO;
import com.xbongbong.pro.statistic.result.pojo.vo.ResultDataSeriesChartVO;
import com.xbongbong.pro.statistic.through.pojo.dto.ThroughDTO;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import com.xbongbong.saas.enums.dictionary.DictionaryEnum;
import com.xbongbong.sys.domain.entity.UserEntity;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.index.query.QueryBuilders.termQuery;

/**
 * 跟进记录
 *
 * @author 徐俊杰
 * @version v1.0
 * @date 2019/2/20 19:13
 * @since v1.0
 */
@Component
public class CrmCommunicateResult extends ChartResultParentService implements ChartResultSystem, ChartResultPk, PanoramaResult {
    private static final Logger LOG = LoggerFactory.getLogger(CrmCommunicateResult.class);
    @Resource
    private CrmCustomerResult crmCustomerResult;

    /**
     * 系统指标公共接口
     *
     * @param chartResultPojo     请求系统指标接口需要用到的pojo类（内部存系统指标统计时需要的参数）
     * @param chartResultDetailVO 统计需要渲染的图（表---可能同时存在，可能某一个存在）塞入该vo
     * @return java.util.Objects 塞入过统计结果的chartResultDetailVO
     * @throws XbbException
     * @author zcp
     * @date 2019/2/14 10:23
     * @version v1.0
     * @since v1.0
     */
    @Override
    public Object getTarget(ChartResultPojo chartResultPojo, ChartResultDetailVO chartResultDetailVO) throws XbbException {
        SystemCodeEnum systemCodeEnum = chartResultPojo.getSystemCodeEnum();
        switch (systemCodeEnum) {
            case COMMUNICATE_ADD_HOME:
            case COMMUNICATE_ADD_CHART:
                return communicateAdd(chartResultPojo, chartResultDetailVO);
            case COMMUNICATE_ADD_CHART_DAY:
                return communicateDayMan(chartResultPojo, chartResultDetailVO);
            case COMMUNICATE_TYPE_CHART:
                return communicateType(chartResultPojo, chartResultDetailVO);
            default:
                break;
        }
        return null;
    }

    @Override
    public Object getValueTarget(ChartResultPojo chartResultPojo) throws XbbException {
        SystemCodeEnum systemCodeEnum = chartResultPojo.getSystemCodeEnum();
        switch (systemCodeEnum) {
            case COMMUNICATE_ADD_BOARD:
                return communicateAddBoard(chartResultPojo);
            default:
                break;
        }
        return null;
    }

    @Override
    public Object getPkTarget(UserEntity userEntity, ChartResultPkPojo chartResultPkPojo, ChartResultPkDetailVO chartResultPkDetailVO) throws XbbException {
        SystemCodeEnum systemCodeEnum = chartResultPkPojo.getSystemCodeEnum();
        switch (systemCodeEnum) {
            //pk、完成情况（员工排行）
            case PK_COMMUNICATE_ADD:
            case PERFORMANCE_COMMUNICATE_ADD:
                return pkCommunicateAdd(userEntity, chartResultPkPojo, chartResultPkDetailVO);
            default:
                break;
        }
        return null;
    }

    /**
     * 系统pk范围规则指标公共接口
     *
     * @param userEntity            登录员工
     * @param chartResultPkPojo     pk参数
     * @param chartResultPkDetailVO 塞入pk结果
     * @return java.lang.Object
     * @throws XbbException
     * @author zcp
     * @date 2019/3/18 15:34
     * @version v1.0
     * @since v1.0
     */
    @Override
    public Object getPkRuleTarget(UserEntity userEntity, ChartEntity chartEntity, ChartResultPkPojo chartResultPkPojo, ChartResultPkDetailVO chartResultPkDetailVO) throws XbbException {
        SystemCodeEnum systemCodeEnum = chartResultPkPojo.getSystemCodeEnum();
        switch (systemCodeEnum) {
            //pk、完成情况（员工排行）
            case PK_COMMUNICATE_ADD:
            case PERFORMANCE_COMMUNICATE_ADD:
                return pkRuleCommunicateAdd(userEntity,chartEntity, chartResultPkPojo, chartResultPkDetailVO);
            default:
                break;
        }
        return null;
    }

    @Override
    public Object customer(PanoramaPojo panoramaPojo) throws XbbException {
        PanoramaEnum panoramaEnum = panoramaPojo.getPanoramaEnum();
        switch (panoramaEnum) {
            case CUSTOMER_COMMUNICATE_ADD:
                return panoramaCustomerCommunicateAdd(panoramaPojo);
            default:
                break;
        }
        return null;
    }

    /**
     * 跟进次数
     *
     * @param chartResultPojo 请求系统指标接口需要用到的pojo类（内部存系统指标统计时需要的参数）
     * @param chartResultDetailVO 统计需要渲染的图（表---可能同时存在，可能某一个存在）塞入该vo
     * @return java.lang.Object
     * @throws XbbException
     * @author 徐俊杰
     * @date 2019/2/21 21:02
     * @since v1.0
     */
    public Object communicateAdd(ChartResultPojo chartResultPojo, ChartResultDetailVO chartResultDetailVO) throws XbbException {
        ThroughDTO throughDTO = new ThroughDTO(chartResultPojo, chartResultPojo.getSystemCodeEnum());
        //是否画入表格内 0否1是
        Integer tableFlag = 1;
        String legend = SystemCodeEnum.COMMUNICATE_ADD_BOARD.getName();
        String unit = systemChartHelp.getUnit(I18nMessageUtil.getMessage(CommonConstant.TIMES));
        ElasticAggsPojo elasticAggsPojo = communicateAdd2ElasticAggsPojo(chartResultPojo, ValueTypeEnum.ARRAY_TYPE);
        Boolean totalFlag = true;
        String valueTitle = I18nMessageUtil.getMessage(ChartI18Constant.COMMUNICATION_TIMES_CONTENT);
        return systemChartHelp.packageResult4One(elasticAggsPojo, chartResultPojo, chartResultDetailVO, throughDTO, tableFlag, legend, unit, totalFlag, valueTitle);
    }

    /**
     * 新增跟进记录--日人均
     * 横坐标月份，纵坐标日人均数量
     *
     * @param chartResultPojo 请求系统指标接口需要用到的pojo类（内部存系统指标统计时需要的参数）
     * @param chartResultDetailVO 统计需要渲染的图（表---可能同时存在，可能某一个存在）塞入该vo
     * @return java.lang.Object
     * @throws XbbException
     * @author 徐俊杰
     * @date 2019/2/25 9:00
     * @since v1.0
     */
    public Object communicateDayMan(ChartResultPojo chartResultPojo, ChartResultDetailVO chartResultDetailVO) throws XbbException {
        //获取timeType
        FiscalYearTimePojo fiscalYearTimePojo = chartResultPojo.getFiscalYearTimePojo();
        Integer timeType = fiscalYearTimePojo.getTimeType4DefaultMonth();
        ResultCountListVO addResultCountListVO = communicateAdd2ResultCountListVO(chartResultPojo, chartResultDetailVO);
        ResultCountListVO customerTotalUserIdVO = crmCustomerResult.customerTotalUserId(chartResultPojo);
        List<Integer> addCommunicateCountList = addResultCountListVO.getResultList();
        Integer addCommunicateCountTotal = addResultCountListVO.getTotal();
        Integer userCountTotal = customerTotalUserIdVO.getTotal();
        double manAvgAddCommunicateCount = (userCountTotal == 0) ? 0 : Arith.div(addCommunicateCountTotal, userCountTotal);
        //在此判断是否为自定义类型（自定义天数另处理）
        int betweenDays = 0;
        if(timeType == TimeTypeEnum.CUSTOM.getCode()){
            betweenDays = DateUtil.betweenDays(chartResultPojo.getStartTime(), chartResultPojo.getEndTime());
        }
        //总日人均跟进次数
        double perDayAddCommunicateCount = ChartResultUtil.getAverageDay(timeType, manAvgAddCommunicateCount * 1.0, 2,betweenDays);
        ElasticAggsPojo elasticAggsPojo = new ElasticAggsPojo();
        List<AggsBucketsPojo> rateList = elasticAggsPojo.getBuckets();
        for (int i = 0; i < addCommunicateCountList.size(); i++) {
            //算出每个桶的timeType
            Integer perTimeType = ChartResultUtil.getAverageTimeType(timeType);
            Integer addCount = addCommunicateCountList.get(i);
            //人均
            double mCount = (userCountTotal == 0) ? 0 : Arith.div(addCount, userCountTotal);
            //日均
            double pCount = ChartResultUtil.getAverageDay(perTimeType, mCount * 1.0, 2,betweenDays);
            AggsBucketsPojo ratePojo = new AggsBucketsPojo("", String.valueOf(pCount));
            rateList.add(ratePojo);
        }
        elasticAggsPojo.setTotal(String.valueOf(perDayAddCommunicateCount));
        elasticAggsPojo.setBuckets(rateList);

        ThroughDTO throughDTO = new ThroughDTO(chartResultPojo, chartResultPojo.getSystemCodeEnum());
        //是否画入表格内 0否1是
        Integer tableFlag = 1;
        String legend = SystemCodeEnum.COMMUNICATE_ADD_CHART_DAY.getName();
        String unit = "";
        Boolean totalFlag = false;
        String valueTitle = "";
        return systemChartHelp.packageResult4One(elasticAggsPojo, chartResultPojo, chartResultDetailVO, throughDTO, tableFlag, legend, unit, totalFlag, valueTitle);
    }

    /**
     * 跟进次数（简报看板）
     *
     * @param chartResultPojo 内部存系统指标统计时需要的参数
     * @return java.lang.String
     * @author 徐俊杰
     * @date 2019/3/13 17:16
     * @since v1.0
     */
    public String communicateAddBoard(ChartResultPojo chartResultPojo) throws XbbException {
        ChartResultRedisPojo chartResultRedisPojo = new ChartResultRedisPojo(chartResultPojo, SystemCodeEnum.COMMUNICATE_ADD_BOARD);
        String redisKey = systemChartHelp.createSysStatisticsRedisKey(chartResultRedisPojo);
        String redisResult = paasRedisHelper.getValue(RedisPrefixConstant.SYS_STATISTICS, redisKey);
        if (StringUtil.isNotEmpty(redisResult)) {
            return redisResult;
        }
        BoolQueryBuilder boolQueryBuilder = chartQueryHelp.communicateQuery4UserLimitStart(chartResultPojo);
        ElasticAggsPojo elasticAggsPojo = esHelper.elasticAggs(IndexTypeEnum.IDX_SAAS_CUSTOMER_COMMUNICATE, boolQueryBuilder, null);
        redisResult = elasticAggsPojo.getTotal();
        //置入缓存
        paasRedisHelper.setValue(RedisPrefixConstant.SYS_STATISTICS, redisKey, redisResult, RedisTimeConstant.TINY_DURATION);
        return redisResult;
    }

    /**
     * 客户全景图--跟进次数
     * @param panoramaPojo
     * @return java.lang.String
     * @author zcp
     * @date 2019/6/3 15:29
     * @since v1.0
     * @version v1.0
     */
    public String panoramaCustomerCommunicateAdd(PanoramaPojo panoramaPojo) throws XbbException {
        String dataAttr = CustomerCommunicateEnum.getEsAttr4Keyword(CustomerCommunicateEnum.CUSTOMER_NAME);
        BoolQueryBuilder boolQueryBuilder = chartQueryHelp.panoramaQuery4Base(panoramaPojo, "creatorId.keyword", dataAttr, panoramaPojo.getDataId());
        //只统计跟进记录类型，不统计项目日志（当为项目日志时，该值不为0）
        boolQueryBuilder.filter(termQuery("logType", 0));
        ElasticAggsPojo elasticAggsPojo = esHelper.elasticAggs(IndexTypeEnum.IDX_SAAS_CUSTOMER_COMMUNICATE, boolQueryBuilder, null);
        return elasticAggsPojo.getTotal();
    }

    /**
     * 跟进方式
     *
     * @param chartResultPojo 请求系统指标接口需要用到的pojo类（内部存系统指标统计时需要的参数）
     * @param chartResultDetailVO 统计需要渲染的图（表---可能同时存在，可能某一个存在）塞入该vo
     * @return java.lang.Object
     * @author 徐俊杰
     * @date 2019/2/25 8:58
     * @since v1.0
     */
    public Object communicateType(ChartResultPojo chartResultPojo, ChartResultDetailVO chartResultDetailVO) throws XbbException {
        ChartResultRedisPojo chartResultRedisPojo = new ChartResultRedisPojo(chartResultPojo, SystemCodeEnum.COMMUNICATE_TYPE_CHART);
        String redisKey = systemChartHelp.createSysStatisticsRedisKey(chartResultRedisPojo);
        String value = paasRedisHelper.getValue(RedisPrefixConstant.SYS_STATISTICS, redisKey);
        Object result;
        if (value != null) {
            try {
                result = JsonHelperUtil.parseObject(value, ChartResultDetailVO.class);
                return result;
            } catch (Exception e) {
                //不作处理  解析异常走正常查询逻辑更新缓存
            }
        }
        String corpid = chartResultPojo.getCorpid();
        //查询出跟进记录的表单id
        PaasFormEntityExt paasFormEntityExt = paasFormModel.getByBusinessType(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), corpid);
        //查询出跟进方式list
        List<ItemPoJo> typeList = dataDictionaryModel.getDictionaryList4Saas(DictionaryEnum.COMMUNICATE_TYPE, corpid, paasFormEntityExt.getId());

        /*--------处理查询条件--------*/
        BoolQueryBuilder boolQueryBuilder = chartQueryHelp.communicateQuery4UserLimitStart(chartResultPojo);

        String fieldType = CustomerCommunicateEnum.getEsAttr4Keyword(CustomerCommunicateEnum.TYPE);
        List<ResultDataSeriesChartVO> list = systemChartHelp.getDataDictionaryDataSeries(IndexTypeEnum.IDX_SAAS_CUSTOMER_COMMUNICATE, boolQueryBuilder, fieldType, typeList);
        String tableName = CustomerCommunicateEnum.TYPE.getAttrName();

        ThroughDTO throughDto = new ThroughDTO(chartResultPojo, chartResultPojo.getSystemCodeEnum());
        StatisticResultPieInfoDTO statisticResultPieInfoDto = new StatisticResultPieInfoDTO(SystemCodeEnum.COMMUNICATE_TYPE_CHART.getName(), list, throughDto);
        List<StatisticResultPieInfoDTO> pieInfoDtoList = Collections.singletonList(statisticResultPieInfoDto);
        result = systemChartHelp.packageResult4Pie(tableName, pieInfoDtoList, chartResultPojo, chartResultDetailVO);
        paasRedisHelper.setValue(RedisPrefixConstant.SYS_STATISTICS, redisKey, result, TimeConstant.TINY_DURATION);
        return result;
    }
    /**
     * 跟进次数pk
     * @param userEntity 登录员工信息
     * @param chartResultPkPojo pk参数
     * @param chartResultPkDetailVO 塞入pk结果
     * @return com.xbongbong.pro.statistic.pojo.vo.ChartResultPkDetailVO
     * @throws XbbException
     * @author zcp
     * @date 2019/3/19 21:27
     * @since v1.0
     * @version v1.0
     */
    public ChartResultPkDetailVO pkCommunicateAdd(UserEntity userEntity, ChartResultPkPojo chartResultPkPojo, ChartResultPkDetailVO chartResultPkDetailVO) throws XbbException {
        //PK_COMMUNICATE_ADD与PERFORMANCE_COMMUNICATE_ADD共用一份缓存
        ChartResultRedisPojo chartResultRedisPojo = new ChartResultRedisPojo(chartResultPkPojo, SystemCodeEnum.PK_COMMUNICATE_ADD);
        String redisKey = systemChartHelp.createSysStatisticsRedisKey(chartResultRedisPojo);
        String redisResult = paasRedisHelper.getValue(RedisPrefixConstant.SYS_STATISTICS, redisKey);
        ChartResultPkDetailVO redisChartResultPkDetailVO = JsonHelperUtil.parseObject(redisResult, ChartResultPkDetailVO.class);
        if (Objects.nonNull(redisChartResultPkDetailVO)) {
            return redisChartResultPkDetailVO;
        }
        //塞入跟进记录相应查询条件
        BoolQueryBuilder boolQueryBuilder = chartQueryHelp.communicateQuery4Base(false, chartResultPkPojo, true);
        //以用户userId分组
        TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("aggs01").field("creatorId.keyword");
        termsAggregationBuilder.executionHint(ElasticConstant.EXECUTION_HINT);
        int pkType = chartResultPkPojo.getPkType();
        redisChartResultPkDetailVO = pkHelp.getPkResult4Count(userEntity, chartResultPkPojo, chartResultPkDetailVO, IndexTypeEnum.IDX_SAAS_CUSTOMER_COMMUNICATE, boolQueryBuilder, termsAggregationBuilder, pkType);
        //置入缓存
        paasRedisHelper.setValue(RedisPrefixConstant.SYS_STATISTICS, redisKey, redisChartResultPkDetailVO, RedisTimeConstant.TINY_DURATION);
        return redisChartResultPkDetailVO;
    }

    /**
     * 跟进次数pk
     * @param userEntity 登录员工信息
     * @param chartResultPkPojo pk参数
     * @param chartResultPkDetailVO 塞入pk结果
     * @return com.xbongbong.pro.statistic.pojo.vo.ChartResultPkDetailVO
     * @throws XbbException
     * @author zcp
     * @date 2019/3/19 21:27
     * @since v1.0
     * @version v1.0
     */
    public ChartResultPkDetailVO pkRuleCommunicateAdd(UserEntity userEntity, ChartEntity chartEntity, ChartResultPkPojo chartResultPkPojo, ChartResultPkDetailVO chartResultPkDetailVO) throws XbbException {
        ChartResultRedisPojo chartResultRedisPojo = new ChartResultRedisPojo(chartResultPkPojo, SystemCodeEnum.PK_COMMUNICATE_ADD, RedisConstant.PK_RULE);
        String redisKey = systemChartHelp.createSysStatisticsRedisKey(chartResultRedisPojo);
        String redisResult = paasRedisHelper.getValue(RedisPrefixConstant.SYS_STATISTICS, redisKey);
        ChartResultPkDetailVO redisChartResultPkDetailVO = JsonHelperUtil.parseObject(redisResult, ChartResultPkDetailVO.class);
        if (Objects.nonNull(redisChartResultPkDetailVO)) {
            return redisChartResultPkDetailVO;
        }
        //塞入跟进记录相应查询条件
        BoolQueryBuilder boolQueryBuilder = chartRuleQueryHelp.communicateQuery4Base(true, chartEntity, chartResultPkPojo, true);
        //以用户userId分组
        TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("aggs01").field("creatorId.keyword");
        termsAggregationBuilder.executionHint(ElasticConstant.EXECUTION_HINT);
        int pkType = chartResultPkPojo.getPkType();
        redisChartResultPkDetailVO = pkRuleHelp.getPkResult4Count(userEntity, chartEntity, chartResultPkPojo, chartResultPkDetailVO, IndexTypeEnum.IDX_SAAS_CUSTOMER_COMMUNICATE, boolQueryBuilder, termsAggregationBuilder, pkType);
        //置入缓存
        paasRedisHelper.setValue(RedisPrefixConstant.SYS_STATISTICS, redisKey, redisChartResultPkDetailVO, RedisTimeConstant.TINY_DURATION);
        return redisChartResultPkDetailVO;
    }

    //-------------------private方法-------------------
    /**
     * 跟进次数：该方法获取出总数、和各个桶内数值list，不会封装成图表需要的数据格式
     * @param chartResultPojo
     * @param chartResultDetailVO
     * @return com.xbongbong.pro.statistic.pojo.vo.ResultCountListVO 
     * @throws XbbException
     * @author zcp
     * @date 2019/2/25 11:02
     * @since v1.0
     * @version v1.0
     */
    private ResultCountListVO communicateAdd2ResultCountListVO(ChartResultPojo chartResultPojo, ChartResultDetailVO chartResultDetailVO) throws XbbException {
        ElasticAggsPojo elasticAggsPojo = communicateAdd2ElasticAggsPojo(chartResultPojo, ValueTypeEnum.ARRAY_TYPE);
        return systemChartHelp.getResultCountListVO(elasticAggsPojo);
    }
    /**
     * 获取跟进次数的ElasticAggsPojo
     *
     * @param chartResultPojo 请求系统指标接口需要用到的pojo类（内部存系统指标统计时需要的参数）
     * @return com.xbongbong.paas.elasticsearch.pojo.ElasticAggsPojo
     * @author 徐俊杰
     * @date 2019/2/23 11:20
     * @since v1.0
     */
    private ElasticAggsPojo communicateAdd2ElasticAggsPojo(ChartResultPojo chartResultPojo, ValueTypeEnum valueTypeEnum) throws XbbException {
        //统一用一个systemCode
        ChartResultRedisPojo chartResultRedisPojo = new ChartResultRedisPojo(chartResultPojo, SystemCodeEnum.COMMUNICATE_ADD_CHART, valueTypeEnum);
        String redisKey = systemChartHelp.createSysStatisticsRedisKey(chartResultRedisPojo);
        String value = paasRedisHelper.getValue(RedisPrefixConstant.SYS_STATISTICS, redisKey);
        ElasticAggsPojo result;
        if (value != null) {
            try {
                result = JsonHelperUtil.parseObject(value, ElasticAggsPojo.class);
                return result;
            } catch (Exception e) {
                //不作处理  解析异常走正常查询逻辑更新缓存
            }
        }
        /*--------处理查询条件--------*/
        BoolQueryBuilder boolQueryBuilder = chartQueryHelp.communicateQuery4UserLimitStart(chartResultPojo);
        result = systemChartHelp.getCount4Agg(chartResultPojo, valueTypeEnum, IndexTypeEnum.IDX_SAAS_CUSTOMER_COMMUNICATE,
                boolQueryBuilder, CustomerCommunicateEnum.getEsAttr4Keyword(CustomerCommunicateEnum.COMMUNICATE_TIME));
        paasRedisHelper.setValue(RedisPrefixConstant.SYS_STATISTICS, redisKey, result, TimeConstant.TINY_DURATION);
        return result;
    }
}
